/******************************************************************************
* set up globals
*****************************************************************************/


*****************************************************************************
**  Packages
*****************************************************************************

/*
ssc inst _gwtmean
ssc inst estout
ssc inst maptile
ssc inst spmap
ssc inst binscatter
ssc inst listtex
ssc inst parmest
ssc inst ftools
ssc inst winsor
ssc inst reghdfe
reghdfe, compile
ftools, compile
*/




*****************************************************************************
** run geographic level
*****************************************************************************

**  at cz/cnty/zip level
* also indi level for sumstats only

* cz (main sum stats)
global Geo cz
global GeoCZ 1

// ** county
// global Geo cnty
// global GeoCZ 0

// // ** zip level (main mover analysis, also use this for two-way FE, although all versions contain the same data)
// global Geo zip
// global GeoCZ 0

// ** individual level for sum stats
// global Geo indi
// global GeoCZ 0


*****************************************************************************
** mover event study what to run
*****************************************************************************

** generate each type of outputs
global run_hist 0
global run_binscatter 1
global run_event_study 0


** main version 4 years pre and 8 years post-move (=0)
** robust: 4 years pre and post larger sample  (=1)
global evt_sample_version 0

** different event study to run
** dummies in the event study regression function:
// run base
// positive vs negative move, 
// young vs old at move (40 cut-off),
// within state vs across states
// geo origin/destination X event time
// whether we separate by movers cohort (pre vs post bapcpa)
// by credits score tercile
// remake using stored data
global evt_base 1
global evt_posneg 0
global evt_age 0
global evt_xst 0
global evt_od_fe 0
global evt_cohort 0
global evt_score 0
global evt_remake 0



*****************************************************************************
** place vs person two-way fixed effects
*****************************************************************************

** state level for place effect correlates only
global fe_st_estimate  0
global fe_st_merge_est 1


** estimate and bootstrap
global fe_cz_boot_id 0
global fe_cz_estimate  0
global fe_cz_merge_est 1




*****************************************************************************
**  variable lists
*****************************************************************************

*** key varlist
global allTuVars unpdcoly3 colbaly3 unpdcol colmed colexmed colbal medbal exmedbal ccdqy3 ccdqy3_cond ccdq ccdq_cond ccdq_fl ccdq_fl_cond bkrty3 bkrt7y3 bkrt13y3

*financial distress measures
global keyTuVars   unpdcoly3 colbaly3  unpdcol colmed colexmed colbal medbal exmedbal  ccdqy3 ccdqy3_cond  bkrty3 bkrt7y3 bkrt13y3  
global keyTuVars   unpdcoly3 ccdqy3 bkrt7y3 bkrt13y3 


*finanicla distress measures for movers
global keyMvVars  unpdcoly3 unpdcol  colmed colexmed  ccdqy3 bkrt7y3 bkrt13y3  


*order in tables
global keyMvVarsShow  unpdcoly3 unpdcol  colmed colexmed  ccdqy3 bkrt7y3 bkrt13y3  

* short list of variables we display in paper
global keyMvVarsMain unpdcoly3 ccdqy3 bkrt7y3 bkrt13y3



*****************************************************************************
**  sums tats set up
*****************************************************************************


*** sum stats as of year, wtd
global sumStatsyr       2015
global sumStatsM        "06"
global rankStabYr1      2001
global rankStabYr2      2015
global wtd              "[aw = numobs]"


global czXlsNumColStart  6          //numerical data starts from the 6th column in the CZ level XLS data from spark

global zipXlsNumColStart 7          //numerical data starts from the 7th column in the zip level XLS data from spark


*** map
global nqMap 10 //number of quantile in map



*****************************************************************************
**  mover set up
*****************************************************************************


*** mover geo level and group by variables
if "$Geo"=="cz"{
	global ext = "_cznodraw"
}
if "$Geo"=="zip"{
	global ext = "_zipnodraw"
// 	global ext = "_zipnodrawage"	
}
if "$Geo"=="cnty"{
	global ext = "_cntynodraw"
}

*level of variation in the data, not depend on geographic level for delta
global varL cz_o cz_d cnty_o cnty_d zip_o zip_d age10


*** more level at which we compute delta
* add age10 if also condition delta on age10
global deltaGeo ${Geo}
if "$ext"=="_zipnodrawage"{
	global deltaGeo age10
}

*min/max of 10 year age bucket
global youngCut 20
global oldCut   70


*time cut for dose-response plots
global binsPre -12
global binsPost 12
global binsPre2 -4


*binned scatter plots number of bins
global nBins 20

*time frame for event study
* main version require 4 years pre-move and 8 years post move, effectively looking movers in 2004 - 2007
* robust analysis, require 4 years pre-move and 4 years post-move
global evtQ 16
global evtQpre  16
if $evt_sample_version==0{
	global evtQpost 32
}
else{
	global evtQpost 16
}
global evtQstep 4

*store mover estimates 16 quartesr (4 years) post move to then summarize in a table
global mvRegQ 16   


*format plots
global betaPos 11
global ringPos 0
global figDcPt 3
global tabDcPt 4



**number of bootstrap samples in two-way FE
global nBS 50


*****************************************************************************
**  covariates set up
*****************************************************************************



*** set of covariates we project state means/place effects on
global proj_covar ///
		 median_sa garnish chp7fee chp13fee   /// legal factors
		creditlimit_bal numbr_sqmi national /// credit supply 
		inc_median inc_gini house_own  house_median  own_vehicle edu_bachelor job_employed covered_any hospital_fp // lpcal econ factors


*load programs
do "${stataRoot}/01_programs.do"
